<admintpl file="header" />
</head>

<body>
<div class="wrap js-check-wrap">
    <div class="wrap js-check-wrap">
        <ul class="nav nav-tabs">
            <li><a href="{:U('NewsSet/defaultIndex')}">栏目列表</a></li>
            <li class="active"><a href="{:U('NewsSet/add')}">添加栏目</a></li>
        </ul>

        <form method="post" class="form-horizontal js-ajax-form" action="{:U('Admin/NewsSet/addColumn')}">
        <div class="control-group">
            <label class="span1 control-label" style="width: 80px;">栏目类别：</label>
            <div class="span7">
                <label class="span1 radio" style="width: 60px;">
                    <input type="radio" id="type1" name="type" value="1" checked="checked">
                    常规栏目
                </label>
                <label class="span1 radio" style="width: 60px;">
                    <input type="radio" id="type2" name="type" value="2" >
                    本地栏目
                </label>
            </div>
            <div>
                <table class="table table-hover table-bordered table-list">
                <tr id="set_colname" >
                    <td style="width: 200px;">栏目名称</td>
                    <td>
                       <input type="text" name="column_name" value="" >
                    </td>
                </tr>

                <tr id="set_weight">
                    <td style="width: 200px;">权重</td>
                    <td>
                        <input type="text" name="weight" value="" >
                    </td>
                </tr>
                </table>
            </div>
        <div id="set_admin">
            <div class="control-group" style="margin-top: 20px;">
                <label class="span1 control-label" style="width: 90px;">设置管理员</label>
                <div class="span3">
                    <input type="text"  style="width: 556px;" name="administrators" id="administrator" readonly="readonly">
                </div>
            </div>

            <div class="control-group">
                <label class="span1 control-label" style="width: 90px;"></label>
                <div class="span3">
                    <foreach name="admin_infos" key="admin_key" item="admin_value">
                        <input name="admin_checkbox"  admin_name="{$admin_value['username']}"  type="checkbox"   value="{$admin_value['admin_id']}" />{$admin_value['username']}<br/>
                    </foreach>
                </div>
            </div>
        </div>
            <input type="hidden" name="admin_hidden_ids" id="admin_hidden_ids" value="">
        </div>
        <div class="form-actions" style="padding-left:260px;">
            <button type="submit" class="btn btn-primary js-ajax-submit" data-type="add">保存</button>
            &nbsp;&nbsp;<a class="btn" href="{:U('Admin/NewsSet/defaultIndex')}">{:L('BACK')}</a>
        </div>
</form>
    </div>

</div>
<script src="__PUBLIC__/js/common.js"></script>

<script>
    function add_check(){
        var name = $("input[name='column_name']").val();
        var flag = false;
        $.ajax({
            type:"post",
            async:false,
            url:"{:U('Admin/Movement/filter_words')}",
            data:'name='+name,
            dataType:"text",
            success:function(data){
                if(data){
                    if(confirm('您编辑的内容涉及敏感词'+data+'是否继续操作')){
                        flag= true;
                    }else{
                        flag= false;
                    }
                }else{
                    flag = true;
                }
            }
        });
        return flag;
    }
    window.onload = function() {
        var radios = document.getElementsByName('type');
        for (var i = 0; i < radios.length; i++) {
            radios[i].indexs = i + 1;
            radios[i].onchange = function () {
                if (this.checked) {
                    if($('input:radio:checked').val() == 2){
                        document.getElementById("set_admin").style.display="none";
                    }else{
                        document.getElementById("set_admin").style.display="block";
                    }

                }
            }
        }
    }
    $(function(){
        $("[name='admin_checkbox']").click(function(){
            var admin_id = $(this).val();
            var admin_name = $(this).attr('admin_name');


            var admin_hidden_ids = $("#admin_hidden_ids").val();
            var admin_values = $("#administrator").val();

            var ids_arr = admin_hidden_ids.split(",");
            var values_arr = admin_values.split(",");


            if(ids_arr.indexOf(admin_id) == '-1'){
                admin_hidden_ids+=admin_id+',';
                admin_values+=admin_name+',';
                $("#administrator").val(admin_values);
                $("#admin_hidden_ids").val(admin_hidden_ids);
            }else{
                $.each(ids_arr,function(index,item){
                    if(item==admin_id){
                        ids_arr.splice(index,1);
                        values_arr.splice(index,1);
                    }
                })
                admin_hidden_ids = ids_arr.join(",");
                admin_values = values_arr.join(",");
                $("#administrator").val(admin_values);
                $("#admin_hidden_ids").val(admin_hidden_ids);
            }
        })
    })

</script>

</body>
</html>